/* eslint-disable */
import { createRouter, createWebHashHistory } from "vue-router";

//  页面
import mapLayout from "@/mapLayout"
import dataInput from "@/views/dataInput/dataInput"
import toolBar from "@/views/toolBar/toolBar"
import mapControl from "@/views/mapControl/mapControl"
import dataContainer from "@/views/dataContainer/dataContainer"
import SelectResult from "@/views/SelectResult/SelectResult"
import update from "@/views/update/update"
import uploadCAD from "@/views/uploadCAD/uploadCAD"

import PubSub from "pubsub-js";

const routes = [
    // 首页
    {
        path: "/",
        redirect: "/mapLayout",
    },
    // 地图首页
    {
        path: "/mapLayout/",
        component: mapLayout,
        //  children中路由对象的path值不需要斜杠'/'，components必须带s
        children: [
            // 地图
            {
                path: "",
                components: {
                    default: mapLayout,
                    "mapControl": mapControl,
                    "toolBar": toolBar,
                },
                beforeEnter(to, from, next) {
                    let flag
                    switch (from.path) {
                        case "/mapLayout/input":
                            flag = 1
                            break;
                        case "/mapLayout/selectResult":
                            flag = 2
                            break;
                    }
                    PubSub.publish("toMap", { flag })
                    next()
                }
            },
            // 数据填写
            {
                path: "input",
                components: {
                    default: mapLayout,
                    "dataInput": dataInput,
                }
            },
            // 数据展示
            {
                path: "detail",
                components: {
                    default: mapLayout,
                    "mapControl": mapControl,
                    "detail": dataContainer
                },
                beforeEnter(to, from, next) {
                    PubSub.publish("toDetail")
                    next()
                }
            },
            // 查询结果
            {
                path: "selectResult",
                components: {
                    default: mapLayout,
                    "mapControl": mapControl,
                    "detail": SelectResult
                },
                beforeEnter(to, from, next) {
                    PubSub.publish("toSelectResult")
                    next()
                }
            },
            // 标绘更新
            {
                path: "update",
                components: {
                    default: mapLayout,
                    "mapControl": mapControl,
                    "update": update
                },
            },
            // 上传CAD
            {
                path: "uploadCAD",
                components: {
                    default: mapLayout,
                    "mapControl": mapControl,
                    "toolBar": toolBar,
                    "update": uploadCAD,
                }
            }
        ]
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes
});

export default router;